cls

]rsrcmerge "foto.rsr"

sw=screen width
sh=screen height
swh=sw/2
shh=sh/2
cw=200
ch=200
cwh=cw/2
chh=ch/2
mapw=1000
maph=1000
fullscreen mode sw,sh,16

mapsc= init screen (0,0,mapw,maph)
set screen to mapsc
cls
load pict rsrc 128

rendersc=init screen (0,0,cw,ch)
set screen to rendersc
cls
set dport to rendersc

rad=57.295778 'degrees

xpos=mapw/2
ypos=maph/2

a=cw
b=cw*4
z=400
red=.4
hordist=round (z*red)

zspace=z/hordist
dim colspace (hordist)

for row= 1 to hordist
w=(row*hordist)/b
colspace (row)=w/cw
next row

main:

gosub pointpos
gosub getscreen
gosub copyscreen

goto main

pointpos:

speed=0
rotspeed=20

keymap scan
if keymap key ("d") then
   dangle=dangle+rotspeed
endif

if keymap key ("a") then
   dangle=dangle-rotspeed
endif

if keymap key ("w") then
   speed=20
endif

if keymap key ("s") then
   speed=-20
endif

if keymap key ("q") then set screen to console:normal screen:end

if dangle>360 then dangle=dangle-360
if dangle<0 then dangle=dangle+360

angle=dangle/rad

angcosi=cos (angle)
angsine=sin (angle)

xpos=xpos-(angsine*speed)
ypos=ypos+(angcosi*speed)

if xpos<0 then xpos=0
if xpos>mapw then xpos=mapw
if ypos<0 then ypos=0
if ypos>maph then ypos=maph

return

getscreen:

set screen to rendersc
forecolor 30000,30000,65000
rect 0,0,cw,ch

for row = 1 to hordist
   for col= 1 to cw
      relx=(colspace (row)*(a/2))-(colspace (row)*(col-1))
      rely=zspace*(row)
      relan=atn (rely/relx)
      renptan=angle+relan
      relhip=relx/cos (relan)
      ptx=(cos (renptan)*relhip)+xpos
      pty=(sin (renptan)*relhip)+ypos
      
      if ptx>0 and ptx<mapw and pty>0 and pty<maph then
         set screen to mapsc
         get pixel round (ptx),round (pty),red,green,blue
      else
         red=0
         green=30000
         blue=0
      endif
      set screen to rendersc
      dport color red,green,blue
      dplot col-1,ch-row
   next col
next row

return

copyscreen:
copyrect 0,0,cw,ch,swh-cwh,shh-chh,swh+cwh,shh+chh,0,rendersc,console
return